package com.xrz.sxm.aj.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.xrz.sxm.aj.activity.R;
import com.xrz.sxm.aj.base.AdapterBase;
import com.xrz.sxm.aj.entity.ChangshiData;

public class ChangshiAdapter extends AdapterBase<ChangshiData> {
	private Context c;

	public ChangshiAdapter(Context c) {
		this.c = c;
	}

	@Override
	protected View getExView(int position, View view, ViewGroup parent) {
		final ViewHolder holder;
		if (view == null) {
			holder = new ViewHolder();
			view = LayoutInflater.from(c).inflate(R.layout.item_changshi, null);
			view.setTag(holder);
		} else {
			holder = (ViewHolder) view.getTag();
		}
		holder.Tv_title = (TextView) view.findViewById(R.id.text_title);
		holder.Tv_pos = (TextView) view.findViewById(R.id.text_pos);
		holder.Tv_cos = (TextView) view.findViewById(R.id.text_cos);
		holder.Tv_content = (TextView) view.findViewById(R.id.text_content);
		holder.Item_Rel=(RelativeLayout) view.findViewById(R.id.item_rel);
		holder.Tv_title.setText(getList().get(position).getTitle());
		holder.Tv_content.setText(getList().get(position).getContent());
		holder.Tv_pos.setText((position+1)+ "");
		if (holder.Tv_content.getVisibility() == view.GONE) {
			holder.Tv_cos.setText("+");
		} else {
			holder.Tv_cos.setText("-");
		}
		holder.Item_Rel.setOnClickListener(new OnClickListener() {
			@Override
 			public void onClick(View v) {
             if(holder.Tv_content.getVisibility()==View.GONE){
            	 holder.Tv_content.setVisibility(View.VISIBLE);
            	 holder.Tv_cos.setText("-");
             }else{
            	 holder.Tv_content.setVisibility(View.GONE);
            	 holder.Tv_cos.setText("+"); 
             }
			}
		});
		return view;
	}

	class ViewHolder {
		TextView Tv_title;
		TextView Tv_pos;
		TextView Tv_cos;
		TextView Tv_content;
        RelativeLayout Item_Rel;
	}
}
